package com.dubbo.gmail.provider.serviceImp;

import com.dubbo.gmail.api.model.UserModel;
import com.dubbo.gmail.api.service.HelloService;
import com.dubbo.gmail.provider.remoteCache.RemoteCacheProvider;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@DubboService
@Component
public class HelloServiceImpl implements HelloService {

    @Autowired
    RemoteCacheProvider remoteCacheProvider;


    @Override
    public String sayHello(String word) {
        return word + " helloServerImpl";
    }

    @Override
    public String cacheUserModel(UserModel userModel) {
        URL url = RpcContext.getContext().getUrl();
        RpcContext context = RpcContext.getContext();
        System.out.println(userModel.getName());

        System.out.println(url.toServiceString());
        System.out.println(url.toFullString());
        System.out.println(url.toIdentityString());

        remoteCacheProvider.getMap().putIfAbsent(userModel.getPlayerId(), url);
        userModel.setName("pppw");
        return "ok";
    }


}
